package LeetCode.leetcode;

/**
 * 只出现一次的数字
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/8
 * @time: 20:06
 */
public class Test136只出现一次的数字 {
    public static void main(String[] args) {
        int[] nums = {2,2,1,3,1};
        System.out.println(singleNumber(nums));
    }
    public static int singleNumber(int[] nums) {
        if (nums == null || nums.length == 0) {
            throw new RuntimeException("输入不合法！");
        }
        int result = nums[0];
        for (int i = 1; i < nums.length; i++) {
            result = result ^ nums[i];
        }
        return result;
    }
}
